import React, {useEffect, useRef} from 'react';
import hljs from "highlight.js";

export  const CodeBlock = ({ language, code }) => {
    const codeRef = useRef(null);

    useEffect(() => {
        if (codeRef.current) {
            hljs.highlightElement(codeRef.current); // 高亮代码块
        }
    }, []);

    return (
        <pre>
     <code ref={codeRef} className={language}>
        {code}
      </code>
    </pre>
    );
};